/*
Joseph Ratway
Garrett Brown
Bret Parker
*/

//imports
import java.util.*;

public class MediumAI
{
    private Node root1;
	private int depth;
    
    MediumAI(Board state,int depth, int color)
    {
        this.root1 = new Node(null, color, state);
		this.depth=depth;
        this.root1.depth = 0;
        
        MinMax(this.root1, color);
		//call minmaxtree
        for(int i = 0; i < this.root1.getChildren.size(); i++)
        {
            MinMax(this.root1.getChildren.get(i), color);
            if(this.root1.getChildren.get(i).getChildren() == null)
                {
                    break;
                }
            for( int j = 0; j < this.root1.getChildren.get(i).getChildren.size(); j++)
            {
                MinMax(this.root1.getChildren.get(i).getChildren.get(j), color);
                if(this.root1.getChildren.get(i).getChildren.get(j).getChildren() == null)
                {
                    break;
                }
                for(int x = 0; x < this.root1.getChildren.get(i).getChildren.get(j).getChildren.size(); x++)
                {
                    MinMax(this.root1.getChildren.get(i).getChildren.get(j).getChildren.get(x), color);
                }
            }   
        }
        for(int i = 0; i < this.root1.getChildren.size(); i++)
        {
            
            if(this.root1.mMaxScore == this.root1.getChildren.get(i).mMaxScore)
            {
                state.currentBoard = this.root1.currentState;
            }
        }
    }
	
	void MinMax(Node root, color)
	{
	
		int rowChange = 0;
		int colChange = 0;
		int maxSpaces=0;
		int maxRow=0;
		int maxCol=0;
		int x=0;
		int y=0;
		int opponent=0;
		child.numSpaces = 0;
		int validmove=root.currentState.isvalidMove(root.currentState.currentBoard);
        int ID = 0;
		
		if (root.currentState.currentBoard.player==1)
			opponent=2;
		else
			opponent=1;
			
		if(validmove>0)
		{
			for(int i=0;i<8;i++)
            {
					for(int j=0;j<8;j++)
					{
						if(root.currentState.currentBoard[i][j].locationValue == 4)//looks for valid moves then sees of that moves will get more tiles than the last valid move
						{	
							Node child;
							String move="";
							move=root.currentState.currentBoard.changeNumtoChar(j)+i;
							child=new Node(root,color,root.currentState.makeMove(root.currentState.currentBoard,root.currentState.player,move), move;);
				
							for(rowChange = -1; rowChange <= 1; rowChange++)
								for(colChange = -1; colChange <= 1; colChange++)
								{
									if(i + rowChange < 0 || i + rowChange >= 8 ||j + colChange < 0 || j + colChange >= 8 || 
										 (rowChange==0 && colChange== 0))
											continue;
									
									if(root.currentState.currentBoard[i+rowChange][j+colChange].locationValue == opponent)
									{
										x=i+rowChange;
										y=j+colChange;
										for(;;)
										{
											x+=rowChange;
											y+=colChange;
											if(x<0||x>=8||y<0||y>=8)
												break;
											if(boardspace[x][y].locationValue == 0)
												break;
											if(boardspace[x][y].locationValue == player)
											{
												child.numSpaces=0;										
												while(root.currentState.currentBoard[x-=rowChange][y-=colChange].locationValue==opponent)
													child.numSpaces++;	
												break;
											}
										}
									}
								}
								
								
						}
                        //put child node in hash table of parent node
                        root.setChild(ID, child);
                        ID++;
					}
            }	
        }
	
	}
	
	void compMove(int spaces)
	{
		if 
	
	
	
	}
    
}